import { PaginationOptions } from '@iboot-vue/vue-request-fork';

const ibootPagination = {
  currentKey: 'pageNumber',
  pageSizeKey: 'pageSize',
  totalKey: 'totalCount'
} as PaginationType

export interface PaginationType {
  currentKey: string;
  pageSizeKey: string;
  totalKey: string;
  totalPageKey: string;
}
export const pageOption = <R, P extends unknown[] = any>(
  defaultParams?: any,
  pagination?: Partial<PaginationType>
): PaginationOptions<R, P> => {
  const pageSize = 20;
  if (defaultParams) {
    defaultParams.map((d: any) => {
      if (!d.pageSize) {
        d.pageSize = pageSize;
      }
      return d;
    });
  } else {
    defaultParams = [
      {
        pageSize: pageSize
      }
    ];
  }
  return {
    defaultParams: defaultParams,
    manual: false,
    pagination: pagination || ibootPagination
  };
};